package com.example.allshengmedical.experimentnew.activity;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import android.R.color;
import android.R.integer;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Environment;
import android.os.Parcelable;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.example.allshengmedical.R;
import com.example.allshengmedical.base.BaseActivity;
import com.example.allshengmedical.base.BaseApplication;
import com.example.allshengmedical.experimentnew.bean.LayoutTableBean;
import com.example.allshengmedical.experimentnew.presenter.LayoutOnePresent;
import com.example.allshengmedical.experimentnew.view.ILayoutOneView;
import com.example.allshengmedical.experimentrun.activity.RunPreviewActivity;
import com.example.allshengmedical.experimentrun.activity.RunPreviewActivity.StandardListViewAdapter;
import com.example.allshengmedical.mainmenu.activity.MainMenuActivity;
import com.example.allshengmedical.util.ByAlert;
import com.example.allshengmedical.util.FileManagerUtil;
import com.example.allshengmedical.util.LogUtil;
import com.example.allshengmedical.util.SharedPreferencesUtils;
import com.example.allshengmedical.util.SlideCutListView;
import com.example.allshengmedical.util.SlideCutListView.RemoveDirection;
import com.example.allshengmedical.util.SlideCutListView.RemoveListener;


//编辑添加基因盘种类
public class EditLayoutOneActivity extends BaseActivity implements ILayoutOneView, OnClickListener, RemoveListener {

	private LayoutOnePresent layoutOnePresent;
	private RelativeLayout addTargetLine, delTargetLine;

	private PopupWindow menuPopupWindow;
	private boolean menuboo;

	private SlideCutListView standardInfoLv;
	private StandardListViewAdapter standardListViewAdapter;
	public ArrayList<LayoutTableBean> activityLayoutTableBeans;

	private int editPosition;

	private List<String> data_list;
	private ArrayAdapter<String> arr_adapter;

	private Set<Integer> colorList;

	private FileManagerUtil fileManagerUtil;

	private Boolean saveBoo = false;

	// 数据
	String folderName;
	String fileName;
	private String appFilePath = Environment.getExternalStorageDirectory() + "/" + "AllShengMedical";
	StringBuffer contextString = new StringBuffer();

	private TextView warnTv;
	private LinearLayout line;

	public static EditLayoutOneActivity context;

	public static EditLayoutOneActivity getInstence() {
		return context;
	}

	@Override
	protected int setcontent() {
		return R.layout.activity_new_layoutone;
	}

	@Override
	protected void initView() {

		warnTv.setVisibility(View.VISIBLE);
		line.setBackgroundColor(Color.parseColor("#ffffcc"));
		standardInfoLv.setEnabled(false);
		addTargetLine.setEnabled(false);
		delTargetLine.setEnabled(false);

		standardInfoLv.setRemoveListener(this);
		context = this;
		fileManagerUtil = new FileManagerUtil();
		layoutOnePresent = new LayoutOnePresent(this);

		layoutOnePresent.initAppHead();
		layoutOnePresent.initBottomView();

		// 初始化lv
		// initListView();

	}

	@Override
	protected void initData() {
		// 数据
		data_list = new ArrayList<String>();
		if ("SYBR".equals(
				SharedPreferencesUtils.get(EditLayoutOneActivity.this, BaseApplication.BASEINFORMATION_REAGENT, ""))) {
			data_list.add("SYBR Green I");
		} else if ("荧光标记探针"
				.equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this, BaseApplication.BASEINFORMATION_REAGENT,
						""))
				| "taqman".equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
						BaseApplication.BASEINFORMATION_REAGENT, ""))) {
			data_list.add("FAM");

			data_list.add("ROX");
			data_list.add("TEXAS-RED");
			data_list.add("HEX");
			data_list.add("JOE");
			data_list.add("CY3");
			data_list.add("TET");
			data_list.add("CY5");
		} else if ("其他"
				.equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this, BaseApplication.BASEINFORMATION_REAGENT,
						""))
				| "Other".equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
						BaseApplication.BASEINFORMATION_REAGENT, ""))) {
			data_list.add("FAM");
			data_list.add("SYBR Green I");
			data_list.add("ROX");
			data_list.add("TEXAS-RED");
			data_list.add("HEX");
			data_list.add("JOE");
			data_list.add("CY3");
			data_list.add("TET");
			data_list.add("CY5");
		}

		// 适配器
		arr_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data_list);
		// 设置样式
		arr_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

		// 配置color的总集合
		colorList = new HashSet<Integer>();
		for (int i = 1; i <= 6; i++) {
			for (int j = 1; j <= 6; j++) {

				colorList.add(i * 10 + j);
				colorList.remove(11);
			}
		}

		getInfo();
		// 配置数据

		activityLayoutTableBeans = new ArrayList<LayoutTableBean>();

		// LogUtil.e(contextString.indexOf(",Aisle") + 7);
		// LogUtil.e(contextString.indexOf(",Color"));

		int index = 0;
		while (!(contextString.indexOf("Aisle", index) <= 0)) {

			// Aisle:
			String aisle;
			aisle = contextString.substring(contextString.indexOf(",Aisle", index) + 7,

					contextString.indexOf(",Color", index));
					// LogUtil.e(aisle);

			// Color
			String color;
			color = contextString.substring(contextString.indexOf(",Color", index) + 7,

					contextString.indexOf(",Target", index));
					// LogUtil.e(color);

			// Target
			String target;
			target = contextString.substring(contextString.indexOf(",Target", index) + 8,

					contextString.indexOf(",Dyes", index));

			// LogUtil.e(target);

			int nextIndex = contextString.indexOf(",Aisle", index) + 7;

			// Dyes
			String dyes;
			if (contextString.indexOf(",Aisle", nextIndex) < 0) {

				try {
					dyes = contextString.substring(contextString.indexOf(",Dyes", index) + 6,
							contextString.indexOf(",,dataSourceListBlock1", index));
				} catch (Exception e) {
					dyes = contextString.substring(contextString.indexOf(",Dyes", index) + 6,
							contextString.length() - 1);
				}

				// LogUtil.e(dyes);
			} else {

				dyes = contextString.substring(contextString.indexOf(",Dyes", index) + 6,

						contextString.indexOf(",Aisle", nextIndex));
				// LogUtil.e(dyes);
			}

			index = contextString.indexOf(",Dyes", index) + 5;

			activityLayoutTableBeans.add(new LayoutTableBean(false, Integer.parseInt(aisle.trim()),
					Integer.parseInt(color.trim()), target, dyes));

		}

		standardListViewAdapter = new StandardListViewAdapter(activityLayoutTableBeans);
		standardInfoLv.setAdapter(standardListViewAdapter);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.addTargetLine:
			layoutOnePresent.addTarget();
			break;

		case R.id.delTargetLine:
			layoutOnePresent.delTarget();
			break;

		default:
			break;
		}

	}

	@Override
	public void initAppHead() {
		setActionBar();
		setSystemTime();

	}

	@Override
	public void initBottomView() {
		setBottomView();

	}

	@Override
	public void addTarget() {
		if (activityLayoutTableBeans.size() >= 32) {
			ByAlert.alert(getString(R.string.editlayoutone_32_));
			return;
		}

		for (int color : colorList) {

			if ("SYBR".equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
					BaseApplication.BASEINFORMATION_REAGENT, ""))) {
				activityLayoutTableBeans.add(new LayoutTableBean(false, 1, color,
						"target" + activityLayoutTableBeans.size(), "SYBR Green I"));

			} else if ("荧光标记探针"
					.equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
							BaseApplication.BASEINFORMATION_REAGENT, ""))
					| "taqman".equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
							BaseApplication.BASEINFORMATION_REAGENT, ""))) {
				activityLayoutTableBeans
						.add(new LayoutTableBean(false, 1, color, "target" + activityLayoutTableBeans.size(), "FAM"));

			} else if ("其他"
					.equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
							BaseApplication.BASEINFORMATION_REAGENT, ""))
					| "Other".equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
							BaseApplication.BASEINFORMATION_REAGENT, ""))) {
				activityLayoutTableBeans
						.add(new LayoutTableBean(false, 1, color, "target" + activityLayoutTableBeans.size(), "FAM"));

			}

			standardListViewAdapter.notifyDataSetChanged();
			standardInfoLv.setSelection(activityLayoutTableBeans.size() - 1);
			colorList.remove(color);
			break;
		}

	}

	@Override
	public void delTarget() {
		ArrayList<LayoutTableBean> beans = new ArrayList<LayoutTableBean>();

		for (int i = 0; i < activityLayoutTableBeans.size(); i++) {
			if (activityLayoutTableBeans.get(i).getChoseen()) {
				beans.add(activityLayoutTableBeans.get(i));
			}

		}
		for (int i = 0; i < beans.size(); i++) {
			activityLayoutTableBeans.remove(beans.get(i));
		}

		standardListViewAdapter.notifyDataSetChanged();
	}

	@Override
	public void changeTaget() {
		// TODO Auto-generated method stub

	}

	@Override
	public void changeColor() {
		// TODO Auto-generated method stub

	}

	@Override
	public void changerFdyes() {
		// TODO Auto-generated method stub

	}

	private void initListView() {

		// activityLayoutTableBeans默认有一个数据
		activityLayoutTableBeans = new ArrayList<LayoutTableBean>();

		if ("SYBR".equals(
				SharedPreferencesUtils.get(EditLayoutOneActivity.this, BaseApplication.BASEINFORMATION_REAGENT, ""))) {
			activityLayoutTableBeans.add(new LayoutTableBean(false, 1, 11, "target", "SYBR Green I"));

		} else if ("荧光标记探针"
				.equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this, BaseApplication.BASEINFORMATION_REAGENT,
						""))
				| "taqman".equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
						BaseApplication.BASEINFORMATION_REAGENT, ""))) {
			activityLayoutTableBeans.add(new LayoutTableBean(false, 1, 11, "target", "FAM"));

		} else if ("其他"
				.equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this, BaseApplication.BASEINFORMATION_REAGENT,
						""))
				| "Other".equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
						BaseApplication.BASEINFORMATION_REAGENT, ""))) {
			activityLayoutTableBeans.add(new LayoutTableBean(false, 1, 11, "target", "FAM"));

		}

		standardListViewAdapter = new StandardListViewAdapter(activityLayoutTableBeans);
		standardInfoLv.setAdapter(standardListViewAdapter);

	}

	private void getInfo() {
		folderName = SharedPreferencesUtils.get(EditLayoutOneActivity.this,
				BaseApplication.FILEMANGER_PREPAREFOLDERPATH, "") + "";
		fileName = SharedPreferencesUtils.get(EditLayoutOneActivity.this, BaseApplication.FILEMANGER_PREPAREFILENAME,
				"") + "";

		String path = appFilePath + "/" + folderName;

		File file = new File(path + "/" + fileName);
		BufferedReader reader = null;
		try {
			System.out.println("以行为单位读取文件内容，一次读一整行:");
			reader = new BufferedReader(new FileReader(file));
			String tempString = null;
			int line = 1;
			// 一次读入一行，直到读入null为文件结束
			while ((tempString = reader.readLine()) != null) {
				// 显示行号
				// System.out.println("line " + line + ": " + tempString);
				// Log.e("--", tempString);
				contextString.append(tempString);
				contextString.append(",");
				line++;
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
					LogUtil.e("!!", contextString + "");

				} catch (IOException e1) {
				}
			}
		}

	}

	// 设置actionBar
	public void setActionBar() {
		Button leftfirstBtn, leftsecondBtn, rightfirstBtn, rightsecondBtn, rightthirdBtn;
		TextView title;

		leftfirstBtn = BindView(R.id.leftfirst_btn);
		leftsecondBtn = BindView(R.id.leftsecond_btn);
		rightfirstBtn = BindView(R.id.rightfirst_btn);
		rightsecondBtn = BindView(R.id.rightsecond_btn);
		rightthirdBtn = BindView(R.id.rightthird_btn);

		title = BindView(R.id.title);

		leftfirstBtn.setVisibility(View.GONE);
		leftfirstBtn.setText(R.string.item_actionbar_menu);
		leftsecondBtn.setVisibility(View.VISIBLE);
		leftsecondBtn.setText(R.string.item_actionbar_home);
		rightfirstBtn.setVisibility(View.GONE);
		rightfirstBtn.setText(R.string.actionBar_new);
		rightsecondBtn.setVisibility(View.GONE);
		rightsecondBtn.setText(R.string.actionBar_saveAs);
		rightthirdBtn.setVisibility(View.GONE);
		rightthirdBtn.setText(R.string.actionBar_save);

		title.setText(R.string.menufragment_layout);

		leftfirstBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (!menuboo) {
					showMenuPopupWindow(v);
					menuboo = !menuboo;
				} else {
					menuPopupWindow.dismiss();
					menuboo = !menuboo;
				}

			}

		});

		leftsecondBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				BaseApplication.getInstance().finishAll();
				Intent intent = new Intent(EditLayoutOneActivity.this, MainMenuActivity.class);
				startActivity(intent);
			}
		});

		rightfirstBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("New");
				Intent intent = new Intent(EditLayoutOneActivity.this, FileManagerActivity.class);
				startActivity(intent);
			}
		});
		rightsecondBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("Save As");
				Intent intent = new Intent(EditLayoutOneActivity.this, FileManagerActivity.class);
				startActivity(intent);
			}
		});
		rightthirdBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				savePopupWindow(v);
			}

		});

	}

	// 获取当前时间的方法
	public void setSystemTime() {

		TextView date, fileName;
		date = BindView(R.id.date);
		fileName = BindView(R.id.file_name);

		// 获取系统时间
		SimpleDateFormat sdfDate = new SimpleDateFormat("MM dd,yyyy");
		date.setText(sdfDate.format(new Date()));

		// 文件路径置空
		fileName.setText(SharedPreferencesUtils.get(this, BaseApplication.FILEMANGER_PREPAREFOLDERPATH, "") + "/"
				+ SharedPreferencesUtils.get(this, BaseApplication.FILEMANGER_PREPAREFILENAME, ""));

	}

	// 设置bottom布局
	public void setBottomView() {
		Button bottomLeftFistBtn, bottomCenterBtn, bottomRightBtn;

		bottomLeftFistBtn = BindView(R.id.bottomLeftFistBtn);
		bottomCenterBtn = BindView(R.id.bottomCenterBtn);
		bottomRightBtn = BindView(R.id.bottomRightBtn);

		bottomLeftFistBtn.setVisibility(View.VISIBLE);
		// bottomCenterBtn.setVisibility(View.VISIBLE);
		bottomRightBtn.setVisibility(View.VISIBLE);

		bottomLeftFistBtn.setText(R.string.bottomView_back);
		// TODO 这个button的文字不确定暂时用A代替
		bottomCenterBtn.setText("A"); // 不确定！！！！！！！
		bottomRightBtn.setText(R.string.bottomView_next);

		bottomLeftFistBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Intent intent = new Intent(EditLayoutOneActivity.this, EditBaseInformationActivity.class);
				startActivity(intent);
				finish();

			}
		});

		bottomCenterBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("A");

			}
		});
		bottomRightBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Boolean colorBoo = false;
				Boolean targetBoo = false;
				for (LayoutTableBean layoutTableBean : activityLayoutTableBeans) {
					if (layoutTableBean.getColor() == 0) {
						colorBoo = true;
					}
					if (TextUtils.isEmpty(layoutTableBean.getTarget()) | "NULL".equals(layoutTableBean.getTarget())) {
						targetBoo = true;
					}
				}
				if (colorBoo) {
					ByAlert.alert(getString(R.string.editlayoutone_color));
				}
				if (targetBoo) {
					ByAlert.alert(getString(R.string.editlayoutone__targetname));
				}
				if (activityLayoutTableBeans.size() == 0) {
					ByAlert.alert(getString(R.string.editlayoutone_cantnull));
				}

				for (int i = 0; i < activityLayoutTableBeans.size() - 1; i++) {

					for (int j = i + 1; j < activityLayoutTableBeans.size() - 1; j++) {

						if (j < activityLayoutTableBeans.size() - 1) {
							if (activityLayoutTableBeans.get(i).getTarget()
									.equals(activityLayoutTableBeans.get(j).getTarget())) {

								ByAlert.alert(getString(R.string.editlayoutone_targetcantbsame));
								return;
							}
						}

					}

				}

				if (!(colorBoo | targetBoo | activityLayoutTableBeans.size() == 0)) {

					if ("Absolute Quantitation"
							.equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
									BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))
							| "绝对定量".equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
									BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))) {

						if (!saveBoo) {
							saveBoo = true;
							// 创建文件
							String folderName = SharedPreferencesUtils.get(EditLayoutOneActivity.this,
									BaseApplication.FILEMANGER_PREPAREFOLDERPATH, "0") + "";
							String fileName = SharedPreferencesUtils.get(EditLayoutOneActivity.this,
									BaseApplication.FILEMANGER_PREPAREFILENAME, "0") + "";
							StringBuffer content = new StringBuffer();
							content.append("\r\n");
							int sumNum = standardListViewAdapter.getCount();
							// 这个方法和之前的一样，先一行一行的全部取出来。然后当遇到本页面数据。我们不做添加然后在这时我们要加入接下来的文件的数据
							String path = appFilePath + "/" + folderName;
							File file = new File(path + "/" + fileName);
							BufferedReader reader = null;
							contextString = new StringBuffer();
							try {
								System.out.println("以行为单位读取文件内容，一次读一整行:");
								reader = new BufferedReader(new FileReader(file));
								String tempString = null;
								int line = 1;
								// 一次读入一行，直到读入null为文件结束
								while ((tempString = reader.readLine()) != null) {
									// 显示行号
									// System.out.println("line " + line + ": "
									// + tempString);
									// Log.e("--", tempString);

									if (tempString.contains("dataSourceListBlock1")) {
										break;
									} else {
										if (line != 1) {
											contextString.append("\r\n");
										}

										contextString.append(tempString);

									}

									line++;
								}
								reader.close();
							} catch (IOException e) {
								e.printStackTrace();
							} finally {
								if (reader != null) {
									try {
										reader.close();
										// LogUtil.e("!!", contextString + "");

									} catch (IOException e1) {
									}
								}
							}

							// try {
							// System.out.println("以行为单位读取文件内容，一次读一整行:");
							// reader = new BufferedReader(
							// new FileReader(file));
							//
							// String tempString = "";
							// int line = 1;
							// // 一次读入一行，直到读入null为文件结束
							// Boolean layoutOneBoolean = false;
							// while ((tempString = reader.readLine()) != null)
							// {
							// // 显示行号
							// // System.out.println("line " + line + ": "
							// // +
							// // tempString);
							// // Log.e("--", tempString);
							// if (tempString.contains("Aisle:")) {
							// layoutOneBoolean = true;
							// continue;
							// } else if (tempString.contains("Color:")) {
							// layoutOneBoolean = true;
							// continue;
							// } else if (tempString.contains("Target:")) {
							// layoutOneBoolean = true;
							// continue;
							// } else if (tempString.contains("Dyes:")) {
							// layoutOneBoolean = true;
							// continue;
							// } else {
							// if (layoutOneBoolean) {
							// // jiashuju
							// for (int i = 0; i < sumNum; i++) {
							// contextString
							// .append("Aisle:"
							// + standardListViewAdapter.layoutTableBeans
							// .get(i)
							// .getAisle());
							// contextString
							// .append("\r\n"
							// + "Color:"
							// + standardListViewAdapter.layoutTableBeans
							// .get(i)
							// .getColor());
							// contextString
							// .append("\r\n"
							// + "Target:"
							// + standardListViewAdapter.layoutTableBeans
							// .get(i)
							// .getTarget());
							// contextString
							// .append("\r\n"
							// + "Dyes:"
							// + standardListViewAdapter.layoutTableBeans
							// .get(i)
							// .getFluorescentDyes());
							//
							// contextString.append("\r\n");
							// }
							// layoutOneBoolean = false;
							// } else {
							// // 啥都不做正常添加
							// }
							// }
							//
							// contextString.append(tempString);
							// contextString.append("\r\n");
							// line++;
							// }
							//
							// reader.close();
							//
							// } catch (IOException e) {
							// e.printStackTrace();
							// } finally {
							// if (reader != null) {
							// try {
							// reader.close();
							//
							// } catch (IOException e1) {
							// }
							// }
							// }

							fileManagerUtil.createFIle(folderName, fileName);
							fileManagerUtil.writeFile(folderName, fileName, contextString + "", false);
						}

						Intent intent = new Intent(EditLayoutOneActivity.this, AbsoluteQuaLayoutActivity.class);
						intent.putExtra("activityLayoutTableBeans", activityLayoutTableBeans);
						startActivity(intent);
//						ByAlert.alert("跳转绝对定量的页面");
					} else if ("Standard Curve Relative Quantitation"
							.equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
									BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))
							| "标准曲线相对定量".equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
									BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))) {

						if (!saveBoo) {
							saveBoo = true;
							// 创建文件
							String folderName = SharedPreferencesUtils.get(EditLayoutOneActivity.this,
									BaseApplication.FILEMANGER_PREPAREFOLDERPATH, "0") + "";
							String fileName = SharedPreferencesUtils.get(EditLayoutOneActivity.this,
									BaseApplication.FILEMANGER_PREPAREFILENAME, "0") + "";
							// 这个方法和之前的一样，先一行一行的全部取出来。然后当遇到本页面数据。我们不做添加然后在这时我们要加入接下来的文件的数据
							String path = appFilePath + "/" + folderName;
							File file = new File(path + "/" + fileName);
							BufferedReader reader = null;
							contextString = new StringBuffer();
							try {
								System.out.println("以行为单位读取文件内容，一次读一整行:");
								reader = new BufferedReader(new FileReader(file));
								String tempString = null;
								int line = 1;
								// 一次读入一行，直到读入null为文件结束
								while ((tempString = reader.readLine()) != null) {
									// 显示行号
									// System.out.println("line " + line + ": "
									// + tempString);
									// Log.e("--", tempString);

									if (tempString.contains("dataSourceListBlock1")) {
										break;
									} else {
										if (line != 1) {
											contextString.append("\r\n");
										}

										contextString.append(tempString);

									}

									line++;
								}
								reader.close();
							} catch (IOException e) {
								e.printStackTrace();
							} finally {
								if (reader != null) {
									try {
										reader.close();
										// LogUtil.e("!!", contextString + "");

									} catch (IOException e1) {
									}
								}
							}

							fileManagerUtil.createFIle(folderName, fileName);
							fileManagerUtil.writeFile(folderName, fileName, contextString + "", false);
						}
						Intent intent = new Intent(EditLayoutOneActivity.this, StandardCurveLayoutActivity.class);
						intent.putExtra("activityLayoutTableBeans", activityLayoutTableBeans);
						startActivity(intent);
//						ByAlert.alert("跳转标准曲线的页面");
					} else if ("⊿Ct Relative Quantitation"
							.equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
									BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))
							| "比较ct值相对定量".equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
									BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))) {

						if (!saveBoo) {
							saveBoo = true;
							// 创建文件
							String folderName = SharedPreferencesUtils.get(EditLayoutOneActivity.this,
									BaseApplication.FILEMANGER_PREPAREFOLDERPATH, "0") + "";
							String fileName = SharedPreferencesUtils.get(EditLayoutOneActivity.this,
									BaseApplication.FILEMANGER_PREPAREFILENAME, "0") + "";
							// 这个方法和之前的一样，先一行一行的全部取出来。然后当遇到本页面数据。我们不做添加然后在这时我们要加入接下来的文件的数据
							String path = appFilePath + "/" + folderName;
							File file = new File(path + "/" + fileName);
							BufferedReader reader = null;
							contextString = new StringBuffer();
							try {
								System.out.println("以行为单位读取文件内容，一次读一整行:");
								reader = new BufferedReader(new FileReader(file));
								String tempString = null;
								int line = 1;
								// 一次读入一行，直到读入null为文件结束
								while ((tempString = reader.readLine()) != null) {
									// 显示行号
									// System.out.println("line " + line + ": "
									// + tempString);
									// Log.e("--", tempString);

									if (tempString.contains("dataSourceListBlock1")) {
										break;
									} else {
										if (line != 1) {
											contextString.append("\r\n");
										}

										contextString.append(tempString);

									}

									line++;
								}
								reader.close();
							} catch (IOException e) {
								e.printStackTrace();
							} finally {
								if (reader != null) {
									try {
										reader.close();
										// LogUtil.e("!!", contextString + "");

									} catch (IOException e1) {
									}
								}
							}

							fileManagerUtil.createFIle(folderName, fileName);
							fileManagerUtil.writeFile(folderName, fileName, contextString + "", false);
						}
						Intent intent = new Intent(EditLayoutOneActivity.this, CompareCtLayoutActivity.class);
						intent.putExtra("activityLayoutTableBeans", activityLayoutTableBeans);
						startActivity(intent);
//						ByAlert.alert("跳转比较ct值页面");
					} else {
						ByAlert.alert("实验类型不匹配！");
					}
				}

			}
		});
	}

	// menu的弹出窗口
	private void showMenuPopupWindow(View v) {

		if (null == menuPopupWindow || !menuPopupWindow.isShowing()) {
			View contentView = LayoutInflater.from(this).inflate(R.layout.fragment_new_basicinformation_menu, null);

			menuPopupWindow = new PopupWindow(contentView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			menuPopupWindow.setBackgroundDrawable(new BitmapDrawable());
			menuPopupWindow.setTouchable(true);
			menuPopupWindow.setOutsideTouchable(true);
			menuPopupWindow.showAsDropDown(v, -40, -3);

			TextView basicInformationTv, layoutTv, methodTv, previewTv;
			basicInformationTv = (TextView) contentView.findViewById(R.id.basicInformationTv);
			layoutTv = (TextView) contentView.findViewById(R.id.layoutTv);
			methodTv = (TextView) contentView.findViewById(R.id.methodTv);
			previewTv = (TextView) contentView.findViewById(R.id.previewTv);

			basicInformationTv.setBackground(getResources().getDrawable(R.color.darkBlue));
			basicInformationTv.setTextColor(this.getResources().getColor(R.color.white));
			layoutTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					ByAlert.alert("跳转页面layout");

				}
			});
			methodTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					ByAlert.alert("跳转页面method");
				}
			});
			previewTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					ByAlert.alert("跳转页面preview");
				}
			});

		} else {
			menuPopupWindow.dismiss();
			menuboo = !menuboo;
		}

	}

	public class StandardListViewAdapter extends BaseAdapter {
		private ArrayList<LayoutTableBean> layoutTableBeans;

		public StandardListViewAdapter(ArrayList<LayoutTableBean> layoutTableBeans) {
			super();
			this.layoutTableBeans = layoutTableBeans;
		}

		public void removeBean(Object layoutTableBean) {
			layoutTableBeans.remove(layoutTableBean);
			activityLayoutTableBeans.remove(layoutTableBean);
			notifyDataSetChanged();

		}

		class ViewHolder {
			TextView numTv, targetTv, aisleTv;
			CheckBox checkBox;
			ImageView colorIv;
			Spinner fluorescentSpinner;
		}

		@Override
		public int getCount() {
			return layoutTableBeans != null ? layoutTableBeans.size() : 0;
		}

		@Override
		public Object getItem(int position) {
			return layoutTableBeans != null ? layoutTableBeans.get(position) : null;
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {
			final ViewHolder holder;
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = LayoutInflater.from(EditLayoutOneActivity.this)
						.inflate(R.layout.item_listview_layout_standard, null);
				holder.aisleTv = (TextView) convertView.findViewById(R.id.aisleTv);
				holder.checkBox = (CheckBox) convertView.findViewById(R.id.checkBox);
				holder.colorIv = (ImageView) convertView.findViewById(R.id.colorIv);
				holder.fluorescentSpinner = (Spinner) convertView.findViewById(R.id.fluorescentSpinner);
				holder.numTv = (TextView) convertView.findViewById(R.id.numTv);
				holder.targetTv = (TextView) convertView.findViewById(R.id.targetTv);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			// holder.aisleTv.setText(layoutTableBeans.get(position).getAisle());
			if (layoutTableBeans.get(position).getChoseen()) {
				holder.checkBox.setChecked(true);
			} else {
				holder.checkBox.setChecked(false);
			}
			if (activityLayoutTableBeans.get(position).getColor() == 0) {
				holder.colorIv.setBackground(getResources().getDrawable(R.color.white));
			} else {
				switch (activityLayoutTableBeans.get(position).getColor()) {
				case 11:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_one_one));
					break;
				case 12:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_one_two));
					break;
				case 13:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_one_three));

					break;
				case 14:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_one_four));

					break;
				case 15:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_one_five));

					break;
				case 16:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_one_six));

					break;
				case 21:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_two_one));
					break;
				case 22:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_two_two));
					break;
				case 23:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_two_three));
					break;
				case 24:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_two_four));
					break;
				case 25:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_two_five));
					break;
				case 26:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_two_six));
					break;
				case 31:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_three_one));
					break;
				case 32:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_three_two));
					break;
				case 33:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_three_three));
					break;
				case 34:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_three_four));
					break;
				case 35:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_three_five));
					break;
				case 36:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_three_six));
					break;

				case 41:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_four_one));
					break;
				case 42:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_four_two));
					break;
				case 43:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_four_three));
					break;
				case 44:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_four_four));
					break;
				case 45:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_four_five));
					break;
				case 46:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_four_six));
					break;
				case 51:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_five_one));
					break;
				case 52:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_five_two));
					break;
				case 53:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_five_three));
					break;
				case 54:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_five_four));
					break;
				case 55:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_five_five));
					break;
				case 56:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_five_six));
					break;
				case 61:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_six_one));
					break;
				case 62:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_six_two));

					break;
				case 63:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_six_three));
					break;
				case 64:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_six_four));
					break;
				case 65:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_six_five));
					break;
				case 66:
					holder.colorIv.setBackground(getResources().getDrawable(R.color.palette_six_six));
					break;
				default:
					break;
				}
			}

			// holder.colorIv.setOnClickListener(new OnClickListener() {
			//
			// @Override
			// public void onClick(View v) {
			// colorList.size();
			//
			// if (activityLayoutTableBeans.get(position).getColor() == 0) {
			// colorPopupWindow(v, position, 0);
			// } else {
			// // colorList.add(activityLayoutTableBeans.get(position)
			// // .getColor());
			// colorPopupWindow(v, position, activityLayoutTableBeans
			// .get(position).getColor());
			// }
			//
			// }
			//
			// });

			holder.numTv.setText(position + 1 + "");
			holder.fluorescentSpinner.setAdapter(arr_adapter);

			if ("SYBR".equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
					BaseApplication.BASEINFORMATION_REAGENT, ""))) {

				holder.fluorescentSpinner.setSelection(0, true);

			} else if ("荧光标记探针"
					.equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
							BaseApplication.BASEINFORMATION_REAGENT, ""))
					| "taqman".equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
							BaseApplication.BASEINFORMATION_REAGENT, ""))) {
				if ("FAM".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(0, true);
				} else if ("ROX".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(1, true);
				} else if ("TEXAS-RED".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(2, true);
				} else if ("HEX".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(3, true);
				} else if ("JOE".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(4, true);
				} else if ("CY3".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(5, true);
				} else if ("TET".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(6, true);
				} else if ("CY5".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(7, true);
				}

			} else if ("其他"
					.equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
							BaseApplication.BASEINFORMATION_REAGENT, ""))
					| "Other".equals(SharedPreferencesUtils.get(EditLayoutOneActivity.this,
							BaseApplication.BASEINFORMATION_REAGENT, ""))) {
				if ("FAM".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(0, true);
				} else if ("SYBR Green I".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(1, true);
				} else if ("ROX".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(2, true);
				} else if ("TEXAS-RED".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(3, true);
				} else if ("HEX".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(4, true);
				} else if ("JOE".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(5, true);
				} else if ("CY3".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(6, true);
				} else if ("TET".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(7, true);
				} else if ("CY5".equals(layoutTableBeans.get(position).getFluorescentDyes())) {
					holder.fluorescentSpinner.setSelection(8, true);
				}
			}

			// holder.fluorescentSpinner
			// .setOnItemSelectedListener(new OnItemSelectedListener() {
			//
			// @Override
			// public void onItemSelected(AdapterView<?> parent,
			// View view, int itposition, long id) {
			// // TextView tv = (TextView) view;
			// // // tv.setTextColor(getResources().getColor(
			// // // R.color.white)); // 设置颜色
			// // // tv.setTextSize(12.0f); // 设置大小
			// // tv.setGravity(Gravity.CENTER_HORIZONTAL); // 设置居中
			//
			// if ("SYBR".equals(SharedPreferencesUtils
			// .get(EditLayoutOneActivity.this,
			// BaseApplication.BASEINFORMATION_REAGENT,
			// ""))) {
			//
			// switch (itposition) {
			//
			// case 1:
			// activityLayoutTableBeans.get(position)
			// .setAisle(1);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("SYBR Green I");
			// holder.aisleTv.setText("1:470/525nm");
			// break;
			// default:
			// break;
			// }
			// } else if ("荧光标记探针".equals(SharedPreferencesUtils
			// .get(EditLayoutOneActivity.this,
			// BaseApplication.BASEINFORMATION_REAGENT,
			// ""))
			// | "taqman".equals(SharedPreferencesUtils
			// .get(EditLayoutOneActivity.this,
			// BaseApplication.BASEINFORMATION_REAGENT,
			// ""))) {
			// switch (itposition) {
			// case 0:
			// activityLayoutTableBeans.get(position)
			// .setAisle(1);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("FAM");
			//
			// holder.aisleTv.setText("1:470/525nm");
			// break;
			//
			// case 1:
			// activityLayoutTableBeans.get(position)
			// .setAisle(2);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("ROX");
			// holder.aisleTv.setText("2:530/571nm");
			// break;
			// case 2:
			// activityLayoutTableBeans.get(position)
			// .setAisle(2);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("TEXAS-RED");
			// holder.aisleTv.setText("2:530/571nm");
			// break;
			// case 3:
			// activityLayoutTableBeans.get(position)
			// .setAisle(3);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("HEX");
			// holder.aisleTv.setText("3:571/612nm");
			// break;
			// case 4:
			// activityLayoutTableBeans.get(position)
			// .setAisle(3);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("JOE");
			// holder.aisleTv.setText("3:571/612nm");
			// break;
			// case 5:
			// activityLayoutTableBeans.get(position)
			// .setAisle(3);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("CY3");
			// holder.aisleTv.setText("3:571/612nm");
			// break;
			// case 6:
			// activityLayoutTableBeans.get(position)
			// .setAisle(3);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("TET");
			// holder.aisleTv.setText("3:571/612nm");
			// break;
			// case 7:
			// activityLayoutTableBeans.get(position)
			// .setAisle(4);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("CY5");
			// holder.aisleTv.setText("4:620/680nm");
			// break;
			//
			// default:
			// break;
			// }
			// } else if ("其他".equals(SharedPreferencesUtils
			// .get(EditLayoutOneActivity.this,
			// BaseApplication.BASEINFORMATION_REAGENT,
			// ""))
			// | "Other".equals(SharedPreferencesUtils
			// .get(EditLayoutOneActivity.this,
			// BaseApplication.BASEINFORMATION_REAGENT,
			// ""))) {
			// switch (itposition) {
			// case 0:
			// activityLayoutTableBeans.get(position)
			// .setAisle(1);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("FAM");
			//
			// holder.aisleTv.setText("1:470/525nm");
			// break;
			// case 1:
			// activityLayoutTableBeans.get(position)
			// .setAisle(1);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("SYBR Green I");
			// holder.aisleTv.setText("1:470/525nm");
			// break;
			// case 2:
			// activityLayoutTableBeans.get(position)
			// .setAisle(2);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("ROX");
			// holder.aisleTv.setText("2:530/571nm");
			// break;
			// case 3:
			// activityLayoutTableBeans.get(position)
			// .setAisle(2);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("TEXAS-RED");
			// holder.aisleTv.setText("2:530/571nm");
			// break;
			// case 4:
			// activityLayoutTableBeans.get(position)
			// .setAisle(3);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("HEX");
			// holder.aisleTv.setText("3:571/612nm");
			// break;
			// case 5:
			// activityLayoutTableBeans.get(position)
			// .setAisle(3);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("JOE");
			// holder.aisleTv.setText("3:571/612nm");
			// break;
			// case 6:
			// activityLayoutTableBeans.get(position)
			// .setAisle(3);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("CY3");
			// holder.aisleTv.setText("3:571/612nm");
			// break;
			// case 7:
			// activityLayoutTableBeans.get(position)
			// .setAisle(3);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("TET");
			// holder.aisleTv.setText("3:571/612nm");
			// break;
			// case 8:
			// activityLayoutTableBeans.get(position)
			// .setAisle(4);
			// activityLayoutTableBeans.get(position)
			// .setFluorescentDyes("CY5");
			// holder.aisleTv.setText("4:620/680nm");
			// break;
			//
			// default:
			// break;
			// }
			// }
			//
			// }
			//
			// @Override
			// public void onNothingSelected(AdapterView<?> parent) {
			// }
			// });
			holder.targetTv.setText(layoutTableBeans.get(position).getTarget());
			// holder.targetTv.setOnClickListener(new OnClickListener() {
			//
			// @Override
			// public void onClick(View v) {
			// editPosition = position;
			// Intent keyBoardIntent = new Intent(
			// EditLayoutOneActivity.this, KeyboardActivity.class);
			//
			// keyBoardIntent.putExtra("folderName", holder.targetTv
			// .getText().toString());
			// keyBoardIntent.putExtra("title", "Target Name");
			//
			// startActivityForResult(keyBoardIntent, 101);
			// }
			// });
			holder.checkBox.setTag(position);
			holder.fluorescentSpinner.setEnabled(false);
			// holder.checkBox
			// .setOnCheckedChangeListener(new OnCheckedChangeListener() {
			//
			// @Override
			// public void onCheckedChanged(CompoundButton buttonView,
			// boolean isChecked) {
			// int i = 0;
			// Iterator<LayoutTableBean> iterator = activityLayoutTableBeans
			// .iterator();
			// while (iterator.hasNext()) {
			// LayoutTableBean bean = iterator.next();
			// if (Integer.parseInt(holder.checkBox.getTag()
			// + "") == i) {
			// bean.setChoseen(isChecked);
			// }
			//
			// i++;
			// }
			// // if (isChecked) {
			// // activityLayoutTableBeans.get(position)
			// // .setChoseen(true);
			// // ByAlert.alert(position
			// // + ":"
			// // + activityLayoutTableBeans
			// // .get(position).getChoseen());
			// // } else {
			// // activityLayoutTableBeans.get(position)
			// // .setChoseen(false);
			// // ByAlert.alert(position
			// // + ":"
			// // + activityLayoutTableBeans
			// // .get(position).getChoseen()
			// // + "");
			// // }
			//
			// }
			// });
			holder.checkBox.setChecked(activityLayoutTableBeans.get(position).getChoseen());

			return convertView;
		}
	}

	@Override
	public void removeItem(RemoveDirection direction, int position) {
		// standardListViewAdapter.removeBean(standardListViewAdapter
		// .getItem(position));
		// position = position + 1;
		switch (direction) {
		// case RIGHT:
		// Toast.makeText(this, "删除第 " + position + "行", Toast.LENGTH_SHORT)
		// .show();
		// break;
		// case LEFT:
		// Toast.makeText(this, "删除第 " + position + "行", Toast.LENGTH_SHORT)
		// .show();
		// break;

		default:
			break;
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		// 点击target名称编辑，返回时传数据
		if (requestCode == 101 && resultCode == 201) {
			activityLayoutTableBeans.get(editPosition).setTarget(data.getStringExtra("result"));
			standardListViewAdapter.notifyDataSetChanged();

		}
		// 点击实验名称编辑，返回时不传数据
		if (requestCode == 101 && resultCode == 202) {

		}

	}

	private void colorPopupWindow(View v, final int position, final int preColor) {
		View conteView = LayoutInflater.from(this).inflate(R.layout.dialog_new_layout_dyes, null);

		ImageView palette11, palette12, palette13, palette14, palette15, palette16, palette21, palette22, palette23,
				palette24, palette25, palette26, palette31, palette32, palette33, palette34, palette35, palette36,
				palette41, palette42, palette43, palette44, palette45, palette46, palette51, palette52, palette53,
				palette54, palette55, palette56, palette61, palette62, palette63, palette64, palette65, palette66;
		palette11 = (ImageView) conteView.findViewById(R.id.palette11);
		palette12 = (ImageView) conteView.findViewById(R.id.palette12);
		palette13 = (ImageView) conteView.findViewById(R.id.palette13);
		palette14 = (ImageView) conteView.findViewById(R.id.palette14);
		palette15 = (ImageView) conteView.findViewById(R.id.palette15);
		palette16 = (ImageView) conteView.findViewById(R.id.palette16);
		palette21 = (ImageView) conteView.findViewById(R.id.palette21);
		palette22 = (ImageView) conteView.findViewById(R.id.palette22);
		palette23 = (ImageView) conteView.findViewById(R.id.palette23);
		palette24 = (ImageView) conteView.findViewById(R.id.palette24);
		palette25 = (ImageView) conteView.findViewById(R.id.palette25);
		palette26 = (ImageView) conteView.findViewById(R.id.palette26);
		palette31 = (ImageView) conteView.findViewById(R.id.palette31);
		palette32 = (ImageView) conteView.findViewById(R.id.palette32);
		palette33 = (ImageView) conteView.findViewById(R.id.palette33);
		palette34 = (ImageView) conteView.findViewById(R.id.palette34);
		palette35 = (ImageView) conteView.findViewById(R.id.palette35);
		palette36 = (ImageView) conteView.findViewById(R.id.palette36);
		palette41 = (ImageView) conteView.findViewById(R.id.palette41);
		palette42 = (ImageView) conteView.findViewById(R.id.palette42);
		palette43 = (ImageView) conteView.findViewById(R.id.palette43);
		palette44 = (ImageView) conteView.findViewById(R.id.palette44);
		palette45 = (ImageView) conteView.findViewById(R.id.palette45);
		palette46 = (ImageView) conteView.findViewById(R.id.palette46);
		palette51 = (ImageView) conteView.findViewById(R.id.palette51);
		palette52 = (ImageView) conteView.findViewById(R.id.palette52);
		palette53 = (ImageView) conteView.findViewById(R.id.palette53);
		palette54 = (ImageView) conteView.findViewById(R.id.palette54);
		palette55 = (ImageView) conteView.findViewById(R.id.palette55);
		palette56 = (ImageView) conteView.findViewById(R.id.palette56);
		palette61 = (ImageView) conteView.findViewById(R.id.palette61);
		palette62 = (ImageView) conteView.findViewById(R.id.palette62);
		palette63 = (ImageView) conteView.findViewById(R.id.palette63);
		palette64 = (ImageView) conteView.findViewById(R.id.palette64);
		palette65 = (ImageView) conteView.findViewById(R.id.palette65);
		palette66 = (ImageView) conteView.findViewById(R.id.palette66);

		for (int color : colorList) {
			if (color == 11) {
				palette11.setVisibility(View.VISIBLE);
			}
			if (color == 12) {
				palette12.setVisibility(View.VISIBLE);
			}
			if (color == 13) {
				palette13.setVisibility(View.VISIBLE);
			}
			if (color == 14) {
				palette14.setVisibility(View.VISIBLE);
			}
			if (color == 15) {
				palette15.setVisibility(View.VISIBLE);
			}
			if (color == 16) {
				palette16.setVisibility(View.VISIBLE);
			}
			if (color == 21) {
				palette21.setVisibility(View.VISIBLE);
			}
			if (color == 22) {
				palette22.setVisibility(View.VISIBLE);
			}
			if (color == 23) {
				palette23.setVisibility(View.VISIBLE);
			}
			if (color == 24) {
				palette24.setVisibility(View.VISIBLE);
			}
			if (color == 25) {
				palette25.setVisibility(View.VISIBLE);
			}
			if (color == 26) {
				palette26.setVisibility(View.VISIBLE);
			}
			if (color == 31) {
				palette31.setVisibility(View.VISIBLE);
			}
			if (color == 32) {
				palette32.setVisibility(View.VISIBLE);
			}
			if (color == 33) {
				palette33.setVisibility(View.VISIBLE);
			}
			if (color == 34) {
				palette34.setVisibility(View.VISIBLE);
			}
			if (color == 35) {
				palette35.setVisibility(View.VISIBLE);
			}
			if (color == 36) {
				palette36.setVisibility(View.VISIBLE);
			}
			if (color == 41) {
				palette41.setVisibility(View.VISIBLE);
			}
			if (color == 42) {
				palette42.setVisibility(View.VISIBLE);
			}
			if (color == 43) {
				palette43.setVisibility(View.VISIBLE);
			}
			if (color == 44) {
				palette44.setVisibility(View.VISIBLE);
			}
			if (color == 45) {
				palette45.setVisibility(View.VISIBLE);
			}
			if (color == 46) {
				palette46.setVisibility(View.VISIBLE);
			}
			if (color == 51) {
				palette51.setVisibility(View.VISIBLE);
			}
			if (color == 52) {
				palette52.setVisibility(View.VISIBLE);
			}
			if (color == 53) {
				palette53.setVisibility(View.VISIBLE);
			}
			if (color == 54) {
				palette54.setVisibility(View.VISIBLE);
			}
			if (color == 55) {
				palette55.setVisibility(View.VISIBLE);
			}
			if (color == 56) {
				palette56.setVisibility(View.VISIBLE);
			}
			if (color == 61) {
				palette61.setVisibility(View.VISIBLE);
			}
			if (color == 62) {
				palette62.setVisibility(View.VISIBLE);
			}
			if (color == 63) {
				palette63.setVisibility(View.VISIBLE);
			}
			if (color == 64) {
				palette64.setVisibility(View.VISIBLE);
			}
			if (color == 65) {
				palette65.setVisibility(View.VISIBLE);
			}
			if (color == 66) {
				palette66.setVisibility(View.VISIBLE);
			}
		}

		final PopupWindow colorTypePopupWindow = new PopupWindow(conteView, LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT, true);

		palette11.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(11);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(11);

				colorTypePopupWindow.dismiss();

			}
		});
		palette12.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(12);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(12);

				colorTypePopupWindow.dismiss();

			}
		});
		palette13.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(13);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(13);

				colorTypePopupWindow.dismiss();

			}
		});
		palette14.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(14);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(14);

				colorTypePopupWindow.dismiss();

			}
		});
		palette15.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(15);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(15);

				colorTypePopupWindow.dismiss();

			}
		});
		palette16.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(16);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(16);

				colorTypePopupWindow.dismiss();

			}
		});

		palette21.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(21);
				colorList.remove(21);

				standardListViewAdapter.notifyDataSetChanged();

				colorTypePopupWindow.dismiss();

			}
		});
		palette22.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(22);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(22);

				colorTypePopupWindow.dismiss();

			}
		});
		palette23.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(23);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(23);

				colorTypePopupWindow.dismiss();

			}
		});
		palette24.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(24);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(24);

				colorTypePopupWindow.dismiss();

			}
		});
		palette25.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(25);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(25);

				colorTypePopupWindow.dismiss();

			}
		});
		palette26.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(26);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(26);

				colorTypePopupWindow.dismiss();

			}
		});
		palette31.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(31);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(31);

				colorTypePopupWindow.dismiss();

			}
		});
		palette32.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(32);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(32);

				colorTypePopupWindow.dismiss();

			}
		});
		palette33.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(33);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(33);

				colorTypePopupWindow.dismiss();

			}
		});
		palette34.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(34);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(34);

				colorTypePopupWindow.dismiss();

			}
		});
		palette35.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(35);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(35);

				colorTypePopupWindow.dismiss();

			}
		});
		palette36.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(36);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(36);

				colorTypePopupWindow.dismiss();

			}
		});
		palette41.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(41);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(41);

				colorTypePopupWindow.dismiss();

			}
		});
		palette42.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(42);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(42);

				colorTypePopupWindow.dismiss();

			}
		});
		palette43.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(43);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(43);

				colorTypePopupWindow.dismiss();

			}
		});
		palette44.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(44);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(44);

				colorTypePopupWindow.dismiss();

			}
		});
		palette45.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(45);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(45);

				colorTypePopupWindow.dismiss();

			}
		});
		palette46.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(46);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(46);

				colorTypePopupWindow.dismiss();

			}
		});
		palette51.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(51);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(51);

				colorTypePopupWindow.dismiss();

			}
		});
		palette52.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(52);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(52);

				colorTypePopupWindow.dismiss();

			}
		});
		palette53.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(53);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(53);

				colorTypePopupWindow.dismiss();

			}
		});
		palette54.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(54);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(54);

				colorTypePopupWindow.dismiss();

			}
		});
		palette55.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(55);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(55);

				colorTypePopupWindow.dismiss();

			}
		});
		palette56.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preColor != 0) {
					colorList.add(preColor);
				}
				activityLayoutTableBeans.get(position).setColor(56);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(56);

				colorTypePopupWindow.dismiss();

			}
		});
		palette61.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				activityLayoutTableBeans.get(position).setColor(61);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(61);
				if (preColor != 0) {
					colorList.add(preColor);
				}
				colorTypePopupWindow.dismiss();

			}
		});
		palette62.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				activityLayoutTableBeans.get(position).setColor(62);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(62);
				if (preColor != 0) {
					colorList.add(preColor);
				}
				colorTypePopupWindow.dismiss();

			}
		});
		palette63.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				activityLayoutTableBeans.get(position).setColor(63);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(63);
				if (preColor != 0) {
					colorList.add(preColor);
				}
				colorTypePopupWindow.dismiss();

			}
		});
		palette64.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				activityLayoutTableBeans.get(position).setColor(64);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(64);
				if (preColor != 0) {
					colorList.add(preColor);
				}
				colorTypePopupWindow.dismiss();

			}
		});
		palette65.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				activityLayoutTableBeans.get(position).setColor(65);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(65);
				if (preColor != 0) {
					colorList.add(preColor);
				}
				colorTypePopupWindow.dismiss();

			}
		});
		palette66.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				activityLayoutTableBeans.get(position).setColor(66);
				standardListViewAdapter.notifyDataSetChanged();
				colorList.remove(66);
				if (preColor != 0) {
					colorList.add(preColor);
				}
				colorTypePopupWindow.dismiss();

			}
		});

		colorTypePopupWindow.setTouchable(true);

		colorTypePopupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}

		});

		colorTypePopupWindow.setBackgroundDrawable(new BitmapDrawable());
		colorTypePopupWindow.setTouchable(true);
		colorTypePopupWindow.setOutsideTouchable(true);
		colorTypePopupWindow.showAtLocation(v, Gravity.CENTER, 0, -15);

	}

	private void savePopupWindow(View v) {
		View conteView = LayoutInflater.from(this).inflate(R.layout.dialog_baseinformation_save, null);

		Button confirmBtn, cancelBtn;

		confirmBtn = (Button) conteView.findViewById(R.id.confirm_btn);
		cancelBtn = (Button) conteView.findViewById(R.id.cancel_btn);

		final PopupWindow popupWindow = new PopupWindow(conteView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
				true);

		popupWindow.setTouchable(true);

		popupWindow.setTouchInterceptor(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}

		});

		popupWindow.setBackgroundDrawable(new BitmapDrawable());
		popupWindow.setTouchable(true);
		popupWindow.setOutsideTouchable(true);
		popupWindow.showAtLocation(v, Gravity.CENTER, 0, 0);

		confirmBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if (!saveBoo) {
					saveBoo = true;
					// 创建文件
					String folderName = SharedPreferencesUtils.get(EditLayoutOneActivity.this,
							BaseApplication.FILEMANGER_PREPAREFOLDERPATH, "0") + "";
					String fileName = SharedPreferencesUtils.get(EditLayoutOneActivity.this,
							BaseApplication.FILEMANGER_PREPAREFILENAME, "0") + "";
					StringBuffer content = new StringBuffer();
					content.append("\r\n");
					int sumNum = standardListViewAdapter.getCount();
					for (int i = 0; i < sumNum; i++) {
						content.append("\r\n" + "Aisle:" + standardListViewAdapter.layoutTableBeans.get(i).getAisle());
						content.append("\r\n" + "Color:" + standardListViewAdapter.layoutTableBeans.get(i).getColor());
						content.append(
								"\r\n" + "Target:" + standardListViewAdapter.layoutTableBeans.get(i).getTarget());
						content.append("\r\n" + "Dyes:"
								+ standardListViewAdapter.layoutTableBeans.get(i).getFluorescentDyes());

					}

					// content.append("\r\n" + "ExperimentID:"
					// + experimentIdEt.getText());
					// content.append("\r\n" + "Experimenter:"
					// + experimenterEt.getText());
					// content.append("\r\n" + "ExperimentType:"
					// + spinnerExperType.getText());
					// content.append("\r\n" + "SampleType:"
					// + spinnerSampleType.getText());
					// content.append("\r\n" + "Reagent:" +
					// spinnerReagent.getText());

					fileManagerUtil.createFIle(folderName, fileName);
					fileManagerUtil.writeFile(folderName, fileName, content + "", true);
				}

				popupWindow.dismiss();
			}

		});
		cancelBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				popupWindow.dismiss();
			}
		});

	}
}
